const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const router = require('./router.js')
const cors = require('cors')

//设置跨域访问
app.use(cors())

//解析请求体
app.use(bodyParser.urlencoded({
    extended: true
}))

//开放静态资源
app.use(express.static('public'))

try {
    //使用路由
    app.use(router)
} catch (err) {
    //简易全局异常处理
    console.log(new Date() + err)
}
//监听端口
let port = 3000
app.listen(port, () => {
    console.log("服务启动成功,端口号为:" + port)
})
